/*
	This file is part of the JKTest
    Copyright (C) 2008 Royce Y. Feng <ryfeng@gmail.com>

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU Affero General Public License version 3
    as published by the Free Software Foundation. You may not use, modify
    or distribute this program under any other version of the
    GNU Affero General Public License.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU Affero General Public License for more details.

    You should have received a copy of the GNU Affero General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

package JKPanels;

import java.awt.Color;
import javax.swing.JLabel;
import javax.swing.JPanel;
import java.util.HashMap;
import java.awt.Dimension;
import java.awt.GridLayout;
import javax.swing.BorderFactory;
import javax.swing.border.TitledBorder;
import javax.swing.BoxLayout;
import java.io.Serializable;

/**
 * 
 * Panel for displaying test results
 * 
 * @author Royce Feng
 */
public class TestResultsPanel extends JPanel implements Serializable {

    private HashMap<String,JLabel> componentMap = new HashMap<String,JLabel>();
    
    // Panels
    private JPanel testNames = new JPanel();
    private JPanel values = new JPanel();
    
    // Panel labels
    private JLabel devices = new JLabel("Devices");
    private JLabel ethernet = new JLabel("Ethernet");
    private JLabel floppy = new JLabel("Floppy");
    //private JLabel openoffice = new JLabel("OpenOffice");
    private JLabel partition = new JLabel("Partitions");
    private JLabel software = new JLabel("Software");
    private JLabel sound = new JLabel("Sound");
    
    // Panel values
    private JLabel devicesVal = new JLabel("Not completed.");
    private JLabel ethernetVal = new JLabel("Not completed.");
    private JLabel floppyVal = new JLabel("Not completed.");
    //private JLabel openofficeVal = new JLabel("Not completed.");
    private JLabel partitionVal = new JLabel("Not completed.");
    private JLabel softwareVal = new JLabel("Not completed.");
    private JLabel soundVal = new JLabel("Not completed.");
    
    /**
     * 
     * Main Constructor for TestResultsPanel. Creates two columns for test and
     * for result.
     * 
     */
    public TestResultsPanel ( String header ) {
        super(new GridLayout(1,2));
        TitledBorder title;
        title = BorderFactory.createTitledBorder(header);
        this.setBorder(title);
        testNames.setLayout(new BoxLayout(testNames,BoxLayout.Y_AXIS));
        values.setLayout(new BoxLayout(values,BoxLayout.Y_AXIS));
        componentMap.put("Devices", devicesVal);
        componentMap.put("Ethernet", ethernetVal);
        componentMap.put("Floppy", floppyVal);
        //componentMap.put("OpenOffice", openofficeVal);
        componentMap.put("Partitions Check", partitionVal);
        componentMap.put("Software", softwareVal);
        componentMap.put("Sound", soundVal);
        devicesVal.setForeground(Color.GRAY);
        ethernetVal.setForeground(Color.GRAY);
        floppyVal.setForeground(Color.GRAY);
        //openofficeVal.setForeground(Color.GRAY);
        partitionVal.setForeground(Color.GRAY);
        softwareVal.setForeground(Color.GRAY);
        soundVal.setForeground(Color.GRAY);
        testNames.add(devices);
        values.add(devicesVal);
        testNames.add(sound);
        values.add(soundVal);
        //testNames.add(openoffice);
        //values.add(openofficeVal);
        testNames.add(partition);
        values.add(partitionVal);
        testNames.add(ethernet);
        values.add(ethernetVal);
        testNames.add(software);
        values.add(softwareVal);
        testNames.add(floppy);
        values.add(floppyVal);
        this.add(testNames);
        this.add(values);
    }

    /**
     *
     * Gets text of a label based on source and value
     *
     * @param source The test name
     */
    public String getValue( String source ) {
        return componentMap.get(source).getText();
    }
    
    /**
     * 
     * Sets text of a label based on source and value
     * 
     * @param source The test name
     * @param value Pass/Fail
     */
    public void valueChanged( String source, String value ) {
        JLabel label = componentMap.get(source);
        label.setText(value);
        if ( value.equals("Not completed.") ) {
            label.setForeground(Color.GRAY);
        } else if ( value.equals("Passed") ) {
            label.setForeground(Color.BLUE);
        } else if ( value.equals("Failed") ) {
            label.setForeground(Color.RED);
        }
    }
    
}
